package com.st.base;

import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;

@Tag(name="基础返回类",description = "所有接口都以此类为基础包装返回")
@Data
public class BaseResult<T> {
    @Schema(description = "业务返回说明，参考统一返回说明")
    private String msg;
    @Schema(description = "业务返回标记，参考统一返回说明")
    private int code;
    @Schema(description = "业务返回数据")
    private T data;

    /*
    返回正确信息的构造器
     */
    public static BaseResult ok(Object data){
        BaseResult r = new BaseResult<>();
        r.setCode(100);
        r.setMsg("success");
        r.setData(data);
        return r;
    }

    /*
    返回错误信息的构造器
     */
    public static BaseResult error(String msg){
        BaseResult r = new BaseResult<>();
        r.setCode(500);
        r.setMsg(msg);
        return r;
    }
}
